/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
 var reverseList = function(head) {
    let reshead;
    while(head){
        let node = new ListNode(head.val);
        node.next=reshead;
        reshead=node;
        head=head.next;
    }
    return reshead;
};